package com.bbs.logic.impl;

import com.bbs.db.iface.AdmininfoDao;
import com.bbs.db.iface.ModerinfoDao;
import com.bbs.db.iface.UserinfoDao;
import com.bbs.db.pers.Admininfo;
import com.bbs.db.pers.Boardinfo;
import com.bbs.db.pers.Moderinfo;
import com.bbs.db.pers.Userinfo;
import com.bbs.logic.iface.UserService;
import java.util.List;

/**
 * @time Nov 11, 2009, 12:36:36 PM
 * @author fdcube
 */
public class UserServiceImpl implements UserService {

    private UserinfoDao userinfoDao;

    public void setUserinfoDao(UserinfoDao userinfoDao) {
        this.userinfoDao = userinfoDao;
    }
    private ModerinfoDao moderinfoDao;

    public void setModerinfoDao(ModerinfoDao moderinfoDao) {
        this.moderinfoDao = moderinfoDao;
    }
    private AdmininfoDao admininfoDao;

    public void setAdmininfoDao(AdmininfoDao admininfoDao) {
        this.admininfoDao = admininfoDao;
    }

    public boolean Register(Userinfo value) {
        return userinfoDao.AddUser(value);
    }

    public boolean Block(Userinfo value) {
        value.setUstatus(0);
        return userinfoDao.UpdateUser(value);
    }

    public boolean Delete(Userinfo value) {
        return userinfoDao.DeleteUser(value);
    }

    public List<Userinfo> GetUsers() {
        return userinfoDao.FindUsers();
    }

    public boolean Appoint(Userinfo value, Boardinfo value1) {
        Moderinfo value2 = new Moderinfo(value1, value);
        return moderinfoDao.AddModerator(value2);
    }

    public boolean AdLogin(Admininfo value) {
        if (admininfoDao.FindAdmin(value).size() > 0) {
            return true;
        } else {
            return false;
        }
    }

    public boolean Depose(Moderinfo value) {
        System.out.println("逻辑层删除版主调用");
        return moderinfoDao.DeleteModerator(value);
    }

    public List<Userinfo> GetUser(Userinfo value) {
        if (value.getUid() != null) {
            return userinfoDao.FindUserById(value);
        }
        return userinfoDao.FindUser(value);
    }

    public boolean UpdateUser(Userinfo value) {
        return userinfoDao.UpdateUser(value);
    }

    public boolean Authorize(Userinfo value) {
        value.setUstatus(1);
        return userinfoDao.UpdateUser(value);
    }
}
